<!DOCTYPE html>
<html lang="en">
  <head>
    <title>workbox-broadcast-update demo</title>
    <meta
      name="workbox-broadcast-update demo"
      content="An example to demonstrate the workbox-broadcast-update module"
    />
    <link
      id="favicon"
      rel="icon"
      href="https://glitch.com/edit/favicon-app.ico"
      type="image/x-icon"
    />
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <style>
      body {
        margin-left: 5%;
        font-family: 'Open Sans', sans-serif;
      }
      ol {
        padding-left: 20px;
      }
      li {
        margin-bottom: 5px;
      }
      button {
        margin: 20px 0;
        font-weight: bold;
      }
    </style>
  </head>
  <body>
    <header>
      <div>
        <h1>workbox-broadcast-update Demo</h1>
      </div>
    </header>

    <ol>
      <li>Open DevTools</li>
      <li>Go to the Console</li>
      <li>
        Click any of the buttons below and view the logs:
        <ul>
          <li>
            <p>
              <button class="trigger-broadcast">Trigger a Broadcast</button>
            </p>
          </li>
        </ul>
      </li>
    </ol>

    <script>
      const triggerBroadcast = document.querySelector('.trigger-broadcast');

      window.addEventListener('load', () => {
        navigator.serviceWorker.register('./sw.js').then((reg) => {
          triggerBroadcast.addEventListener('click', () => {
            const message = {
              command: 'trigger-broadcast',
            };
            reg.active.postMessage(message);
          });

          navigator.serviceWorker.addEventListener('message', (event) => {
            console.log(`Received a message from workbox-broadcast-update.`);
            console.log(event.data);
          });
        });
      });
    </script>

    <a href="https://developers.google.com/web/tools/workbox/modules"
      >Back to Demos</a
    >

    <p>
      <a href="https://developers.google.com/web/tools/workbox">Docs</a> |
      <a href="https://github.com/googlechrome/workbox">GitHub</a> |
      <a href="https://twitter.com/workboxjs">@workboxjs</a>
    </p>
  </body>
</html>
